﻿/* 最后更新 2008-6-10 by 56770.WangLei
'* Copyright www.56770.com */            

function selectall(a) 
{ 
   var a = document.getElementsByTagName("input"); 
   for (var i=0; i<a.length; i++) 
      if (a[i].type == "checkbox") a[i].checked =!a[i].checked; 
} 
function tomove()
{   
   var i = 0;   
   var chkArr = document.getElementsByTagName("input");   
   var page = document.getElementById("page").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";   
   if (param.length == 0)
   {
       alert("请先选择要转移分类的条目！");
   }else{
       var url="Admin_product_list.asp?action=movecategory&id="+param+"&page="+page;   
       window.open(url, 'movecategory', 'width=300,height=240,resizable=0,scrollbars=1,status=no,toolbar=no,location=no,menu=no'); 
   }
}
function tosale()
{   
   var i = 0;   
   var chkArr = document.getElementsByTagName("input");   
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var type = document.getElementById("type").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";   
   if (param.length == 0)
   {
       alert("请先选择要上架的条目！");
   }else{
       location="Admin_product_list.asp?action=changestate&state=0&id="+param+"&zhuangtai="+zhuangtai+"&type="+type+"&sort_id="+sort_id+"&page="+page;  
   }
}
function tocancelsale()
{   
   var i = 0;   
   var chkArr = document.getElementsByTagName("input");   
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var type = document.getElementById("type").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";   
   if (param.length == 0)
   {
       alert("请先选择要下架的条目！");
   }else{
       location="Admin_product_list.asp?action=changestate&state=1&id="+param+"&zhuangtai="+zhuangtai+"&type="+type+"&sort_id="+sort_id+"&page="+page;  
   }
}
function torecom()
{   
   var i = 0;   
   var chkArr = document.getElementsByTagName("input");   
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var type = document.getElementById("type").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";   
   if (param.length == 0)
   {
       alert("请先选择要推荐的条目！");
   }else{
       location="Admin_product_list.asp?action=pstj&stj=0&id="+param+"&zhuangtai="+zhuangtai+"&type="+type+"&sort_id="+sort_id+"&page="+page;  
   }
}
function tocancelrecom()
{   
   var i = 0;   
   var chkArr = document.getElementsByTagName("input");   
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var type = document.getElementById("type").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";   
   if (param.length == 0)
   {
       alert("请先选择要取消推荐的条目！");
   }else{
       location="Admin_product_list.asp?action=pstj&stj=1&id="+param+"&zhuangtai="+zhuangtai+"&type="+type+"&sort_id="+sort_id+"&page="+page;  
   }
}
function deletedeaultpage()
{   
   if(window.confirm("确定要删除吗？")){
       location="tohtml/_html_default.asp?do=delete";  
   }else return;
}
function todelsources()
{   
   var i = 0;   
   var chkArr = document.getElementsByTagName("input"); 
   var page = document.getElementById("page").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";  
   if (param.length == 0)
   {
       alert("请先选择要删除的条目！");
   }else{
       if(window.confirm("确定要删除吗？删除将不能恢复！")){
           location="?action=sources_del&id="+param+"&page="+page;  
       }else return;
   }
}
function todel()
{   
	
   var i = 0;   
   var chkArr = document.getElementsByTagName("input"); 
   var page = document.getElementById("page").value;
   var l_type = document.getElementById("l_type").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";  
   if (param.length == 0)
   {
       alert("请先选择要删除的条目！");
   }else{
       if(window.confirm("确定要删除吗？删除将不能恢复！")){
           location="?action=del&id="+param+"&l_type="+l_type+"&page="+page;  
       }else return;
   }
}
function ConfirmDel()
{
        if(confirm("确定要删除吗？删除将不能恢复！"))
                return true;
        else
                return false;
        
}
function u_Size(num,objname)
{
	var obj=document.getElementById(objname)
	if (parseInt(obj.rows)+num>=3) {
		obj.rows = parseInt(obj.rows) + num;	
	}
	if (num>0)
	{
		obj.width="90%";
	}
}
function runscript(n){
	txtRun=n;window.open("../templates_view.aspx","templates_view")
}
function DoTags(addTags){
	document.addproduct.p_tags.value=addTags+document.addproduct.p_tags.value;
	document.addproduct.p_tags.focus();

}
var n=1;
 function switchSysBar(){
	if (n==1){
	    n=2
 		document.all("frmTitle").style.display="none";
		document.getElementById("arrow").src="images/Btn_open.gif";
		document.getElementById("arrow").alt="伸展";
	}
	else{
		n=1;
		document.all("frmTitle").style.display="";
		document.getElementById("arrow").src="images/Btn_close.gif";
		document.getElementById("arrow").alt="收缩";
	}
}
function cleanDefault(id) {	
		document.getElementById(id).value = "";
		document.getElementById(id).style.color="#000000";
}
	
var i = 1;
function searchselect () {
	if (i % 2 == 0) {
		hiddenmenu();
	} else {
		showmenu();
	}
	i=i+1;
}
function choose(items) {
	switch (items) {
		case 1:
			document.getElementById("searchall").value="请输入商品名称搜索";
			document.all.SearchType.value="Admin_product_list.asp?product_name=";
			document.all.SearchTitle.value="商品管理";
			break;
		case 2:
			document.getElementById("searchall").value="请输入订单编号搜索";
			document.all.SearchType.value="Admin_orders.asp?s_order_number=";
			document.all.SearchTitle.value="订单管理";
			break;
		case 3:
			document.getElementById("searchall").value="请输入会员名称搜索";
			document.all.SearchType.value="admin_user.asp?userid=";
			document.all.SearchTitle.value="注册会员管理";
			break;
	}
	hiddenmenu();
	i = i+1;
}
function showmenu() {
		document.getElementById("searchmenu").style.display="block";
}
function hiddenmenu() {
		document.getElementById("searchmenu").style.display="none";
}
function Indexsearch() {
		right.location.href=''+document.all.SearchType.value+document.all.SearchName.value+'';
		top.document.getElementById('topTitle').innerHTML=''+document.all.SearchTitle.value+'';
}	

function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
   }
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
var s=""; 
for(i=0;i<=document.all("get_product").length-1;i++) 
{ 
	//var s=s+document.addNEWS.get_product.options(i).value+",";  // 原程序
	var s=s+document.getElementById("get_product").options(i).value+","; //WL 改动 2008-1-10
} 
//document.addNEWS.n_product.value=s;  // 原程序
document.getElementById("n_product").value = s;  //WL 改动 2008-1-10
//document.addNEWS.get_n_product.focus();
}

var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function callsearch() {
  var s_keywords = document.getElementById("s_keywords").value;
  var s_sort_id = document.getElementById("s_sort_id").options[document.getElementById("s_sort_id").selectedIndex].value;   
  var url = "admin_news.asp?action=search&s_keywords=" + escape(s_keywords) +"&s_sort_id=" + s_sort_id;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);  
}

function updatePage() {
  if (xmlHttp.readyState < 4) {
	test1.innerHTML="<select multiple size='10' name='list1' style='width:340px;'><option>loading...</option></select>";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	test1.innerHTML=response;
  }
}

function Trim(str){
   if(str.charAt(0) == " "){
   str = str.slice(1);
   str = Trim(str); 
}
return str;
}

function isEmpty(pObj,errMsg){
   var obj = eval(pObj);
   if( obj == null || Trim(obj.value) == ""){
   if (errMsg == null || errMsg =="")
      alert("输入为空!");
   else
      alert(errMsg); 
      obj.focus(); 
      return false;
   }
   return true;
}

 /****** START WangLei 2008-1-10 添加************************/
function ajaxSub(t,url,t2) 
{
	if (url.indexOf("?")==-1)
		url = url + '?t000='+Math.random()
	else
		url = url + '&t000='+Math.random()

	xmlHttp.open("GET", url, true);
	switch (t) {
		case 0 :
			xmlHttp.onreadystatechange = updatePageUnite
			break;
		case 1 :
			xmlHttp.onreadystatechange = getUniteProduct;
			break;
		case 2 :
			xmlHttp.onreadystatechange = setarea2;
			break;
		default :
			//alert('3');
			break;
	} 
	xmlHttp.send(null);  
}
function updatePageUnite() {  
  if (xmlHttp.readyState < 4) {
	test1.innerHTML="<select multiple size='10' name='list1' style='width:240px;'><option>loading...</option></select>";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	test1.innerHTML=response;
  }
}

function getUniteProduct()
{
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	var tArr = response.split('||$$||');
	for (i = 0; i < tArr.length; i++) {
	   var sArr = tArr[i].split('|$|');
		if (sArr.length > 6)
		{
			addUniteRows(sArr[1],sArr[2],sArr[3],sArr[4],"",sArr[5]);
		}
	}
	//sumWeight();
  }
}
function getUniteProduct_re(str)
{
	var tArr = str.split('||$$||');
	for (i = 0; i < tArr.length; i++)
	{
	   var sArr = tArr[i].split('|$|');
		if (sArr.length > 4)
		{
			addUniteRows(sArr[0],sArr[1],sArr[2],sArr[3],sArr[4],sArr[5]);
		}
	}
	sumWeight();
}


function sumSPrice() //计算市场价和,计算重量和
{
	var t = 0;
	var tWeight = 0;
	var uPNum = document.getElementsByName("uPNum");
	var uSprice = document.getElementsByName("uSprice");
	var pWeight = document.getElementsByName("pWeight");
	for(i=0;i<uPNum.length;i++)
	{
		if (uPNum[i].value!="" && uSprice[i].value!="")
		{
			t = t + Number(uPNum[i].value)*Number(uSprice[i].value);
		}
		if (uPNum[i].value!="" && pWeight[i].value!="")
		{
			tWeight = tWeight + Number(uPNum[i].value)*Number(pWeight[i].value);
		}
	}
	addproduct.sprice.value = t;
	addproduct.p_weight.value = tWeight;
}

function sumWeight() //计算重量和
{
	var t = 0;
	var pWeight = document.getElementsByName("pWeight");
	
	for(i=0;i<pWeight.length;i++)
	{
		if (pWeight[i].value!="")
		{
			t = t + Number(pWeight[i].value);
		}
	}
	addproduct.p_weight.value = t;
}

function addUniteRows(v0,v1,v2,v3,v4,v5)
{
	//创建td节点
	var td0= document.createElement("td");
	var td1= document.createElement("td");
	var td2= document.createElement("td");
	var td3= document.createElement("td");
	td3.setAttribute("align","center");
	var td4= document.createElement("td");
	td4.setAttribute("align","center");

	td0.innerHTML = v1+'<INPUT TYPE="hidden" NAME="uBianhao" value="'+v1+'"> <INPUT TYPE="hidden" id="uPid" NAME="uPid" value="'+v0+'"><INPUT TYPE="hidden" NAME="pWeight" id="pWeight" value="'+v5+'">';
	td1.innerHTML = v2+'<INPUT TYPE="hidden" NAME="uProduct_name" value="'+v2+'">';
	td2.innerHTML = v3+'<INPUT TYPE="hidden" NAME="uSprice" value="'+v3+'">';
	td3.innerHTML = '<input type=text name=uPNum size=2 value="'+v4+'" maxlength=3 class=form onkeyup=value=value.replace(\/[^\\d]\/g,\'\');  onblur=sumSPrice();>';
	td4.innerHTML = '<A HREF="#" onclick="return delUniteRows();" >删除</a>';

	//创建tr节点
	var trNode = document.createElement("tr");
	trNode.appendChild(td0);
	trNode.appendChild(td1);
	trNode.appendChild(td2);
	trNode.appendChild(td3);
	trNode.appendChild(td4);

	//创建tbody节点，必须使用tbody，不然无法使用dom方式添家行，只能用insertRow
	var trBody = document.createElement("tbody");
	trBody.appendChild(trNode);
	document.getElementById("tableUP").appendChild(trBody);
}
function delUniteRows(event)
{
	if(event == null)
	{
		event = window.event; // For IE
	}
	var eventObj = event.srcElement? event.srcElement : event.target;   
	var tbodyNode = eventObj.parentNode.parentNode.parentNode;
	var trNode = eventObj.parentNode.parentNode
	var rowIndex = trNode.rowIndex;
	var objTable = document.getElementById("tableUP");

	objTable.removeChild(tbodyNode);
	sumSPrice();
	return false;
	//sumWeight();
}
function getSubmitUniteStr() // 获取提交时绑定商品字符串值
{
	var uPidArr = document.getElementsByName("uPid");
	var uBianhao = document.getElementsByName("uBianhao");
	var uProduct_name = document.getElementsByName("uProduct_name");
	var uSprice = document.getElementsByName("uSprice");
	var uPNum = document.getElementsByName("uPNum");
	var pWeight = document.getElementsByName("pWeight");
	
	if (uPidArr.length < 2)
	{
		alert("捆绑促销您至少要选择两种商品.");
		return false;
	}
	for(i=0;i<uPNum.length;i++)
	{
		if (uPNum[i].value=="")
		{
			alert("请输入正确的产品捆绑数量");
			return false;
			break;
		}
	}
	var tArray = new Array();
	for(i=0;i<uPidArr.length;i++)
	{
		tArray.push(uPidArr[i].value + "|$|" +uBianhao[i].value + "|$|" + uProduct_name[i].value + "|$|" + uSprice[i].value + "|$|" + uPNum[i].value + "|$|" + pWeight[i].value);   
	}
	
	addproduct.productUniteStr.value=tArray.join("||$$||");
	return true;
}
function trim(str) //去空格
{
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function toUpdateOrder()  // WangLei 更新记录排序  2008-1-15
{   
	var i = 0,idStr = "",orderStr="";   
	var a = document.getElementsByTagName("input"); 
	var page = document.getElementById("page").value;
	var pOrder = document.all.p_order;
	for (var i=0; i<a.length; i++) 
	{
		if (a[i].type == "checkbox") idStr+=a[i].value +",";
	}
	for (var i=0; i<pOrder.length; i++) 
	{
		orderStr+=pOrder[i].value+",";
	}
	if (idStr.length == 0 || pOrder.length==0)
	{
		alert("暂无内容更新！");
	}else{
		//if (window.confirm("确定要更新记录排序吗？"))
		//{
			location.href="?action=updateOrder&id="+idStr+"&pOrder="+orderStr+"&page="+page;  
		//}else return;
	}
}
function toUpdateGradeIco()  // WangLei 更新记录排序  2008-3-10
{   
	var i = 0,icoStr="";   
	var grade_ico = document.all.grade_ico;
	for (var i=0; i<grade_ico.length; i++) 
	{
		icoStr+=grade_ico[i].value+",";
	}
	if (icoStr.length == 0 )
	{
		alert("暂无内容可更新！");
		return;
	}else{
		//alert(icoStr);
		location.href="?action=updateGradeIco&icoStr="+icoStr;  
	}
}

 /****** END WangLei 2008-1-10 添加************************/
 /****配送地区 2008-3-12 by 56770.WangLei*****/
function setarea2() {  
  if (xmlHttp.readyState < 4) {
	//test1.innerHTML="loading...";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	area2_div_id.innerHTML=response;
  }
}
/********批量删除 2008-3-12 by 56770.WangLei*******************/
function todels(urlstr)
{
   var i = 0;   
   var chkArr = document.getElementsByTagName("input"); 
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked) param+=chkArr[i].value +",";  
   if (param.length == 0)
   {
       alert("请先选择要删除的条目！");
   }else{
       if(window.confirm("确定要删除吗？删除将不能恢复！")){
		   //alert(urlstr + "&id=" + param);
           location= urlstr + "&id=" + param;  
       }else return;
   }
}
/************************************/
function toUpdateDeliverPrice()  // WangLei 更新配送方式价格  2008-6-10
{   
	var i = 0,idStr = "",priceStr="";   
	var a = document.getElementsByTagName("input"); 
	var page = document.getElementById("page").value;
	var pPrice = document.getElementsByName("d_price");
	for (var i=0; i<a.length; i++) 
	{
		if (a[i].type == "checkbox") idStr+=a[i].value +",";
	}
	for (var i=0; i<pPrice.length; i++) 
	{
		priceStr+=pPrice[i].value+",";
	}
	if (idStr.length == 0 || pPrice.length==0)
	{
		alert("暂无内容更新！");
	}else{
		//if (window.confirm("确定要更新记录吗？"))
		//{
			location.href="?action=updatePrice&id="+idStr+"&pPrice="+priceStr+"&page="+page;  
		//}else return;
	}
}
